package org.openmrs.validator;

import org.openmrs.ObligationContext;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

public class ObligationContextValidator implements Validator {
	
	@SuppressWarnings("unchecked")
	public boolean supports(Class c) {
		return c.equals(ObligationContext.class);
	}
	
	@Override
	public void validate(Object obj, Errors errors) {
		ObligationContext context = (ObligationContext) obj;
		if (context == null) {
			errors.rejectValue("policy", "error.general");
		} else {
			ValidationUtils.rejectIfEmptyOrWhitespace(errors, "obligationId", "error.policyname");
		}
	}
	
}
